/**
 * Copyright (c) 2010-2011 Pierre Labatut
 *
 * This file is part of Space-Chronicles project.
 *
 * Space-Chronicles is free software: you can redistribute it and/or modify it
 * under the terms of its license which may be found in the accompanying
 * LICENSE file or <http://code.google.com/p/space-chronicles/>.
 */
package space.app.common;

import java.awt.CardLayout;
import java.awt.LayoutManager;
import javax.media.opengl.awt.GLCanvas;
import space.annotation.EventThreadConfined;

/**
 *
 * @author Pierre
 */
public class JOGLPanel extends javax.swing.JPanel {

    @EventThreadConfined
    private GLCanvas canvas;

    {
        //This code runs in event dispatch thread
        initComponents();
    }

    public JOGLPanel() {
    }

    public JOGLPanel(boolean isDoubleBuffered) {
        super(isDoubleBuffered);
    }

    public JOGLPanel(LayoutManager layout) {
        super(layout);
    }

    public JOGLPanel(LayoutManager layout, boolean isDoubleBuffered) {
        super(layout, isDoubleBuffered);
    }

    
    @EventThreadConfined
    public void setCanvas(GLCanvas canvas) {
        if (canvas == null) {
            throw new NullPointerException();
        }
        //This code runs in event dispatch thread
        if (this.canvas != null) {
            throw new IllegalStateException("Initialization failure. A canvas has already been set");
        }

        this.canvas = canvas;
        JOGLPanel.this.add(canvas, "GL");
        final CardLayout cl = (CardLayout) JOGLPanel.this.getLayout();
        cl.last(JOGLPanel.this);
    }

    @EventThreadConfined
    public void display() {
        if (canvas != null) {
            canvas.display();
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLoadingPanel = new javax.swing.JPanel();
        jProgressBar1 = new javax.swing.JProgressBar();

        setLayout(new java.awt.CardLayout());

        jLoadingPanel.setLayout(new javax.swing.BoxLayout(jLoadingPanel, javax.swing.BoxLayout.LINE_AXIS));

        jProgressBar1.setIndeterminate(true);
        jProgressBar1.setString("Loading ...");
        jProgressBar1.setStringPainted(true);
        jLoadingPanel.add(jProgressBar1);

        add(jLoadingPanel, "card2");
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jLoadingPanel;
    private javax.swing.JProgressBar jProgressBar1;
    // End of variables declaration//GEN-END:variables
}
